import * as db from '@/framework/infra/util/dbUtil'

export default class TableSetting {
  static saveDefaultSearchParam(param = {}) {
    const defaultSearchParam = TableSetting.getDefaultSearchParam()
    Object.assign(defaultSearchParam, param)
    db.set('tableDefaultSearch', defaultSearchParam)
  }

  static getDefaultSearchParam() {
    return {...db.get('tableDefaultSearch')} || {}
  }

  static getDefaultLocalSearchParam() {
    return {...db.get('tableDefaultLocalSearch_' + location.hash)} || {}
  }

  static saveDefaultLocalSearchParam(param = {}) {
    const defaultSearchParam = TableSetting.getDefaultLocalSearchParam()
    Object.assign(defaultSearchParam, param)
    db.set('tableDefaultLocalSearch_' + location.hash, defaultSearchParam)
  }

  static getDefaultLocalFormCachedParam() {
    return {...db.get('tableDefaultLocalFormCached_' + location.hash)} || {}
  }

  static saveDefaultLocalFormCachedParam(param = {}) {
    const defaultSearchParam = TableSetting.getDefaultLocalFormCachedParam()
    Object.assign(defaultSearchParam, param)
    db.set('tableDefaultLocalFormCached_' + location.hash, defaultSearchParam)
  }
}
